package com.yzs.base.view;

import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

public class ViewCompatPagerAdapter<T extends View> extends PagerAdapter {

    private List<T> mList;

    public ViewCompatPagerAdapter(List<T> list) {
        this.mList = list;
    }

    @Override
    public int getCount() {
        if (mList == null)return 0;
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        final View view = mList.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(mList.get(position));
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return String.valueOf(mList.get(position).getTag());
    }
}
